﻿Imports System.IO

Public Class FitHelper

    Private Const SystemTimeFlag As UInt32 = &H10000000

    Private Shared BaseDate As Date = New Date(1989, 12, 31, 0, 0, 0, DateTimeKind.Utc)
    Private Shared DevicePowerOn As Date

    Public Shared Function TranslateDateTime(Value As UInt32) As DateTime
        If Value < SystemTimeFlag Then
            Return DevicePowerOn.AddSeconds(Value)
        Else
            Return BaseDate.AddSeconds(Value)
        End If
    End Function

    Public Shared Sub SetDevicePowerOnDate(d As Date)
        DevicePowerOn = d
    End Sub

    Public Shared Sub ReadUnknownField(Reader As BinaryReader, FieldDef As FieldDefinition)
        Debug.WriteLine("processing unknown field")
        Reader.ReadBytes(FieldDef.Size)
    End Sub

End Class
